<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<DecisionMaking.BusinessLogic.Model.CueModel>" MasterPageFile="~/Views/Shared/Site.Master" %>
<%@ Import Namespace="DecisionMaking.WebApp" %>
<%@ Import Namespace="MvcContrib.UI.MenuBuilder" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server"><%=Model.CueId == null ? "New" : "Edit"%> Cue</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MenuContent" runat="server">
    <% Html.Menu(Navigation.MainMenu(Url, Model.EnvironmentId)); %>
</asp:Content>

<asp:Content runat="server" ContentPlaceHolderID="MainContent">
    <%= Html.ValidationSummary("Attribute creation was unsuccessful. Please correct the errors and try again.") %>

    <% using (Html.BeginForm()) { %>
        <fieldset>
            <legend>Cue Details</legend>
            <%= Html.HiddenFor(m => m.CueId) %>
        	<%= Html.HiddenFor(m => m.EnvironmentId) %>
            <p class="field-multi-line field-textbox">
                <%= Html.LabelFor(m => m.Name) %>
                <%= Html.TextBoxFor(m => m.Name) %>
                <%= Html.ValidationMessageFor(m => m.Name) %>
            </p>
            <p class="field-multi-line field-textbox">
                <%= Html.LabelFor(m => m.Order) %>
                <%= Html.TextBoxFor(m => m.Order)%>
                <%= Html.ValidationMessageFor(m => m.Order)%>
            </p>
        </fieldset>
        <fieldset>
            <legend>Cue Attributes</legend>
            <% for(var i = 0; i < Model.AttributeValues.Count; i++) 
            {
                // we have to copy the attribute into the closure, otherwise only the last value is used in all closure instances
                var index = i;
                   
                // the following block renders a paragraph for each cue attribute value, allowing ASP to automatically bind the inputs into the CueModel
                 %>
                <p class="field-multi-line field-textbox">
                   <%= Html.HiddenFor(m => m.AttributeValues[index].CueAttributeId)%>
                   <label for="AttributeValues[<%= index %>]"><%= Model.AttributeValues[index].Name%></label>
                   <%= Html.TextBoxFor(m => m.AttributeValues[index].Value)%>
                   <%= Html.ValidationMessageFor(m => m.AttributeValues[index].Value)%>
                </p>
            <% } %>
            <p>
                <input type="submit" value="<%= (Model.CueId == null ? "Add" : "Save") %>" />
            </p>            
        </fieldset>
    <% } %>  
</asp:Content>
